///
/// 日志级别
/// 级别顺序：error > warn > info > debug
///
enum LogLevel {
  error, warn, info, debug
}

///
/// 日志帮助类
///
class LogUtils {
  // 日志级别
  static const LogLevel defaultLogLevel = LogLevel.debug;

  ///
  /// 记录debug信息
  ///
  static void debug(String message) {
    if(_isLogDebug(defaultLogLevel)) {
      log("DEBUG", message);
    }
  }
  
  ///
  /// 记录info信息
  ///
  static void info(String message) {
    if(_isLogInfo(defaultLogLevel)) {
      log("INFO", message);
    }
  }
  
  /// 
  /// 记录warn信息
  /// 
  static void warn(String message) {
    if(_isLogWarn(defaultLogLevel)) {
      log("WARN", message);
    }
  }
  
  /// 
  /// 记录error信息
  /// 
  static void error(String message) {
    if(_isLogError(defaultLogLevel)) {
      log("ERROR", message);
    }
  }
  
  /// 
  /// 记录日志
  /// 
  static void log(String logLevelName, String message) {
      DateTime now = new DateTime.now();
      print("$now [$logLevelName] $message");
  }

  ///
  /// 是否记录debug信息
  ///
  static bool _isLogDebug(LogLevel level) {
    return _isLogInfo(level) || LogLevel.debug == level;
  }

  /// 
  /// 是否记录info信息
  /// 
  static bool _isLogInfo(LogLevel level) {
    return _isLogWarn(level) || LogLevel.info == level;
  }

  /// 
  /// 是否记录warn信息
  /// 
  static bool _isLogWarn(LogLevel level) {
    return _isLogError(level) || LogLevel.warn == level;
  }

  /// 
  /// 是否记录error信息
  /// 
  static bool _isLogError(LogLevel level) {
    return LogLevel.error == level;
  }
}